package main

import "fmt"

/* [序] 结构体继承 */
func main() {
	dog := &Dog{
		Feet: 4,
		//name: "dog",
		Animal: &Animal{
			name: "😂",
		},
	}
	fmt.Printf("原始类型：%#v\n", dog)
	dog.move()
	dog.laugh()
}

type Animal struct {
	name string
}
type Dog struct {
	Feet int8
	//name string
	*Animal //匿名嵌套，并且嵌套的是结构体指针
}

func (a *Animal) move() {
	fmt.Printf("%s会动~\n", a.name)
}
func (d *Dog) laugh() {
	/* [note] 两种写法同样结果，在Dog结构体中未找到name属性则会在匿名结构体Animal中查找该属性
	打开注释掉的name属性即可看出Go中属性查找顺序*/
	fmt.Printf("%s会汪汪汪……\n", d.name)
	fmt.Printf("%s会汪汪汪……\n", d.Animal.name)
}
